<template>
    <div>
        <el-breadcrumb separator="/">
            <el-breadcrumb-item :to="{ name: 'teacherbanji' }">个人中心</el-breadcrumb-item>
        </el-breadcrumb>
        <div class="new-box" v-if="userinfo">
            <el-col :span="12">
                <el-form
                    :model="userinfo" 
                    status-icon 
                    :rules="rules" 
                    ref="ruleForm" 
                    label-width="100px" 
                >   
                    <el-form-item label="姓名" prop="username">
                        <el-input type="text" disabled readonly v-model="userinfo.username" autocomplete="off"></el-input>
                    </el-form-item>
                    <el-form-item label="手机号码" prop="mobile">

                    
                        <el-input type="text" disabled readonly v-model="userinfo.mobile" autocomplete="off"></el-input>
                    </el-form-item>
                    <el-form-item label="邮箱" prop="email">
                        <el-input  v-model="userinfo.email" autocomplete="off"></el-input>
                    </el-form-item>
                    <el-form-item label="QQ号码" prop="qq">
                        <el-input  v-model="userinfo.qq" autocomplete="off"></el-input>
                    </el-form-item>
                    <el-form-item label="院校" prop="school">
                        <el-select  v-model="userinfo.schid"  @change="getBanjiList">
                            <el-option :value="sch.schid" :label="sch.schname" v-for=" (sch,i) in schoolList " :key="i" ></el-option>
                        </el-select>
                    </el-form-item>
                    <el-form-item label="学科" prop="xueke">
                        <el-select  v-model="userinfo.xkid" @change="getBanjiList" >
                            <el-option :value="xk.xkid" :label="xk.xkname" v-for=" (xk,i) in xuekeList " :key="i" ></el-option>
                        </el-select>
                    </el-form-item>
                    <el-form-item label="班级" prop="banji">
                       <el-select  v-model="userinfo.bjid">
                            <el-option :value="bj.bjid" :label="bj.bjname" v-for=" (bj,i) in banjiList " :key="i" ></el-option>
                        </el-select>
                    </el-form-item>
                    <el-form-item>
                        <el-button  type="primary"  @click="updateInfo">提交修改</el-button>
                        <el-button  type="success"  >修改密码</el-button>
                    </el-form-item>
                </el-form>
            </el-col>
        </div>
    </div>
</template>


<script>
import {mapState,mapMutations} from "vuex";
export default {
    data(){
        return {
            // userinfo:{},
            rules:{},
            xuekeList:[],
            schoolList:[],
            banjiList:[]
        }
    },
    methods:{
        updateInfo(){
            this.$axios.post("/vue/updateuserinfo",{
                ...this.userinfo
            }).then(res=>{

            })
        },
        ...mapMutations(['changeuesrinfo']),
        getBanjiList(){
            console.log(this.userinfo.xueke);
            this.$axios.post("/vue/getbanjilist",{
                xk:this.userinfo.xkid,
                sch:this.userinfo.schid
            }).then(res=>{
                this.banjiList = res.data.result;
              
                this.changeuesrinfo({...this.userinfo,bjid:''})

            })
        }
    },
    computed:{
        ...mapState(['userinfo']) 
    },
    watch:{
        userinfo:{
            deep:true,
            handler(newVal){

            }
        }
    },
    mounted(){
        this.$axios.post("/vue/getxueke")
        .then(res=>{
            this.xuekeList = res.data.result;
        })

        this.$axios.post("/vue/getschool")
        .then(res=>{
            this.schoolList = res.data.result;
        })
    }
}
</script>

